/*************************************************************************
> File Name: inet_pton.c
> Author: hzy
> Created Time: 2023-09-18 16:37:35
> Description: 
************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <arpa/inet.h>
 
int main(int argc, char const *argv[])
{
    //将点分十进制数串转换成 32 位无符号整数(inet_pton)
    char ip_buf[] = "10.7.178.190";
    unsigned int ip_value = 0;
    inet_pton(AF_INET, ip_buf, &ip_value);
    printf("%u\n", ip_value);

    //将 32 位无符号整数转换成点分十进制数串(inet_ntop)
    char ip_str[16] = {0};
    inet_ntop(AF_INET, &ip_value, ip_str, sizeof(ip_buf));
    printf("%s\n", ip_str);

    return 0;
}